package com.foreknow.service.impl;

import com.foreknow.dao.DepartmentMapper;
import com.foreknow.entity.Department;
import com.foreknow.entity.DepartmentList;
import com.foreknow.entity.DepartmentModel;
import com.foreknow.entity.Deptcategoryid;
import com.foreknow.service.DepartmentService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    //单独删除
    @Override
    public int updateByPrimaryKey(Integer id) {
        return departmentMapper.updateByPrimaryKey(id);
    }
    //批量删除
    @Transactional
    @Override
    public int updateByPrimaryKeyList(List<Integer> id) {
        try{
            for (int i:id){
                departmentMapper.updateByPrimaryKey(i);
            }
        }catch(Exception e) {
            throw new RuntimeException("删除失败！"+e.getMessage());
        }
        return 1;
    }
    //单独添加
    @Override
    public int insert(Department record) {
        if (record== null){
            return 0;
        }
        return departmentMapper.insert(record);
    }
    //修改信息
    @Override
    public int updateByPrimaryKeySelective(Department record) {
        return departmentMapper.updateByPrimaryKeySelective(record);
    }
    //根据id查询（单）
    @Override
    public DepartmentModel selectByPrimaryKey(Integer id) {
        return departmentMapper.selectByPrimaryKey(id);
    }
    //查询全部信息（分页）
    @Override
    public List<DepartmentModel> SelectDepartmentAll(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return departmentMapper.SelectDepartmentAll();
    }
    //查询全部信息（不分页）
    @Override
    public List<DepartmentModel> SelectDepartmentAll() {
        return departmentMapper.SelectDepartmentAll();
    }
    //模糊查询 缩写（分页）
    @Override
    public List<DepartmentModel> departmentFuzzyByName(int pageNum,int pageSize,String condition,String name) {
        PageHelper.startPage(pageNum,pageSize);
        return departmentMapper.departmentFuzzyByName(condition,name);
    }
    //模糊查询 缩写（不分页）
    @Override
    public List<DepartmentModel> departmentFuzzyByName(String condition,String name) {
        return departmentMapper.departmentFuzzyByName(condition,name);
    }
    //查询科室列表
    @Override
    public List<Deptcategoryid> SelectDeptcategoryid() {
        return departmentMapper.SelectDeptcategoryid();
    }
    //查询科室明细列表
    @Override
    public List<DepartmentList> SelectDepartmentList(Integer id) {
        return departmentMapper.SelectDepartmentList(id);
    }



    //查询全部
    @Override
    public List<Department> DPlist() {
        return departmentMapper.DPlist();
    }


}
